package com.earthquake.monitor_system.dao;

import com.earthquake.monitor_system.controller.resultType.UserInfoType;
import com.earthquake.monitor_system.domain.SeismicInformation;
import com.earthquake.monitor_system.domain.UserDomain;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserDao {
    @Select("select username, id,  nickname, phone, birthday, email, address, create_time, avatar from user where status = 0")
    public List<UserDomain> getUser();
    // 判断用户是否已经存在
    @Select("select count(*) from user where username = #{username} and status = 0")
    public Boolean isExistUserName(String username);
    @Insert("INSERT INTO user(username,password,phone) VALUES (#{username},#{password},#{phone});" )
    public Boolean register(String username,String password,String phone);
    @Select("select username, id, nickname, phone, birthday, email, address, create_time from user where id=#{id} and status = 0")
    public UserInfoType getById(int id);
    @Select("select username, id, nickname, username, birthday, email, address, create_time,avatar,phone from user where username = #{username} and password = #{password} and status = 0")
    public  List<UserInfoType>  login(String username, String password);
    @Select("SELECT * FROM user where  status = 0 LIMIT #{startIndex}, #{pageSize}")
    public List<UserDomain> queryUserInfoList(Map<String,Integer> map);
    @Select("select count(*) from user where status = 0")
    public String getUserInfoCount();
    @Update("UPDATE user SET status=1 WHERE id=#{id}")
    public Boolean deleteById(String id);
    @Update("update user set password=#{password} where username= #{userName} and phone=#{phone} and status=0")
    public Boolean changePassword(String password,String userName,String phone);
    @Update("UPDATE user set avatar = #{avatar} where id=#{id}")
    public Boolean  uploadAvatar(String avatar,String id);
    @Update("UPDATE user set nickname=#{nickname},email=#{email},phone=#{phone},birthday=#{birthday},address=#{address} where id=#{id}")
    public Boolean changeUserInfo(UserDomain UserDomain);
}
